/*
 * Copyright (C) 2015-2019 Alibaba Group Holding Limited
 */

#ifndef IO_BOARD_API__H_
#define IO_BOARD_API__H_
#include <stdint.h>
#include <stdbool.h>

#include "canopen/canopen.h"
#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    io_board_lost_connection,
    io_board_working,
    io_board_upgrading,
    io_board_error
} io_board_state_t;

typedef void (*io_board_state_change_cb_t)(const uint8_t board_id, const io_board_state_t state);

typedef void (*io_board_input_change_cb_t)(const uint8_t board_id, const uint8_t input_data_len, const uint8_t *input_level);

/*
 * Function prototype for initialize
 *
 * @param  io_board_state_change call-back when one of io board state changed
 * @param  input_change_cb call-back when gpio input level changed
 *
 * @return  0: success; other: fail.
 */
int32_t io_board_manager_init(io_board_state_change_cb_t io_board_state_change, io_board_input_change_cb_t input_change_cb);

int32_t gpio_output(const uint8_t board_id, const uint8_t gpio_number, const bool set);

uint16_t get_io_board_input_cnt(const uint8_t board_id);

uint16_t get_io_board_output_cnt(const uint8_t board_id);

int32_t inquire_gpio_output(const uint8_t board_id, const uint8_t gpio_number);

int32_t inquire_gpio_input(const uint8_t board_id, const uint8_t gpio_number);

int32_t inquire_gpio_input_batch(const uint8_t board_id, uint32_t *data, const uint16_t start_number, const uint16_t count);//add by maoxinfeng

int32_t inquire_io_board_version(const uint8_t board_id, char *buffer, const uint16_t buffer_len);

int32_t set_gpio_output_batch(uint8_t board_id, uint8_t *data, const uint16_t start_number, const uint16_t count);

int32_t set_gpio_output_default(const uint8_t board_id, const uint8_t len, const uint8_t *data);

int32_t get_gpio_output_default(const uint8_t board_id, const uint8_t buf_len, uint8_t *buf);



#ifdef __cplusplus
}
#endif

#endif /* IO_BOARD_API__H_ */
